package com.chen.microservices.controller;

import com.chen.microservices.pojo.License;
import com.chen.microservices.service.LicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.MessageSource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Locale;


@RestController
@RequestMapping("/v1/organization/{organizationId}/license")
public class LicenseController {

    @Autowired
    private LicenseService licenseService;


    @GetMapping(value = "/{licenseId}")
    public ResponseEntity<License> getLicense(
            @PathVariable("organizationId") String organizationId,
            @PathVariable("licenseId") String licenseId
    ) {
        License license = licenseService.getLicense(licenseId, organizationId);
        return ResponseEntity.ok(license);
    }

//    @PutMapping
//    public ResponseEntity<String> updateLicense(
//            @PathVariable("organizationId")String organizationId,
//            @RequestBody License request
//    ){
//        return ResponseEntity.ok(licenseService.updateLicense(request,organizationId));
//    }

    /**
     * 3-9 p65
     */
    @PostMapping
    public ResponseEntity<String> createLicense(
            @PathVariable("organizationId") String organizationId,
            @RequestBody License request,
            @RequestHeader(value = "Accept-Language", required = false)
                    Locale locale
    ) {
        return ResponseEntity.ok(licenseService.createLicense(request, organizationId, locale));
    }

//    @PostMapping
//    public ResponseEntity<String> createLicense(
//            @PathVariable("organizationId")String organizationId,
//            @RequestBody License request
//    ){
//        return ResponseEntity.ok(licenseService.createLicense(request,organizationId));
//    }

    @DeleteMapping(value = "/{licenseId}")
    public ResponseEntity<String> deleteLicense(
            @PathVariable("organizationId") String organizationId,
            @PathVariable("licenseId") String licenseId
    ) {
        return ResponseEntity.ok(licenseService.deleteLicense(licenseId, organizationId));
    }


}
